require 'login_system'
class Plugin::SearchController < ActionController::Base
  before_filter :set_site_template_root
  def set_site_template_root
    self.class.template_root = "#{RAILS_ROOT}/components/"
    @template.base_path = template_root
  end
  include LoginSystem
  before_filter :login_required, :only => [:config]
  
  def show
  	@plugin=Extplugin.find_by_name("search")
	@config=@plugin.config 
  	if @plugin.activated==1
  	  render(:layout => false)
  	else
  	  render :text => _("not activated")
  	end
  end
  
  def search_result
    if params['search']!=""
      @found1=Media.find(:all, :conditions => ['LOWER(text) LIKE ? ', '%'+params['search'].downcase+'%'])
      @found2=Media.find(:all, :conditions => ['LOWER(title) LIKE ? ', '%'+params['search'].downcase+'%'])
      @found3 = Media.find_tagged_with(params['search'].to_s)
      @found= (@found1 + @found2 + @found3).uniq
    else
      @found=nil  
    end
    @plugin=Extplugin.find_by_name("search")
	@config=@plugin.config 
  	if @plugin.activated==1
  	  render(:layout => false)
  	else
  	  render :text => _("not activated")
  	end
  end
	
  def config
    @plugin=Extplugin.find_by_name("search")
    @config=@plugin.config 
  end
  
end